<?php
namespace app\api\controller\xyvenue;
use app\common\controller\Api;
use app\api\model\xyvenue\recharge\Recharge as RechargeModel;
use app\api\model\xyvenue\recharge\Order as OrderModel;

class Recharge extends Api
{
    
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];
    
    
    /**
     * 保存数据
     * @param Request $request 请求对象
     * @return \think\Response
     */
    public function add()
    {
        // 获取请求数据
        $data =  $this->request->post();
        
        // 进行数据验证
        $validate = new \think\Validate([
            'facevalue' => 'require',
            'buyprice'  => 'require',
            'remark'    => 'require',
            // 'status'   => 'require',
        ]);
        
        if (!$validate->check($data)) {
            // return json(['code' => 0, 'msg' => $validate->getError()]);
        }
        
        // 模型实例化
        $model = new RechargeModel();
        
        $data['status'] =  'normal';
        
        // 数据保存
        if ($model->allowField(true)->save($data)) {
            
            return $this->success('保存成功');
            
        } else {
            return $this->success('保存失败');
        }
    }
    
    
    /**
     * 详情
     */
    public function lists()
    {
        $params = $this->request->post();
        $data = RechargeModel::getList($params);
        $this->success('充值列表', $data);
    }
    
    
     /**
     * 详情
     */
    public function RechargeLists()
    {
        $params = $this->request->post();
        $data = OrderModel::getList($params);
        $this->success('充值列表', $data);
    }
    
    
    
}